package service.impl;

import dao.WzMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pojo.Wz;
import service.WzService;

import java.util.List;

/**
 * 文章表业务逻辑实现类
 */
@Service
public class WzServiceImpl implements WzService {
    @Autowired
    private WzMapper wzMapper;

    @Override
    public Wz findWzById(Integer id) {
        return wzMapper.findWzById(id);
    }

    @Override
    public List<Wz> findAllWz() {
        return wzMapper.findAllWz();
    }

    @Override
    public List<Wz> findWzByCategory(String category) {
        return wzMapper.findWzByCategory(category);
    }

    @Override
    public List<Wz> findHotWz(int limit) {
        return wzMapper.findHotWz(limit);
    }

    @Override
    public List<Wz> searchWz(String keyword) {
        return wzMapper.searchWz(keyword);
    }

    @Override
    public int addWz(Wz wz) {
        // 自动填充访问量默认值
        if (wz.getViewCount() == null) {
            wz.setViewCount(0);
        }
        return wzMapper.addWz(wz);
    }

    @Override
    public int updateWz(Wz wz) {
        return wzMapper.updateWz(wz);
    }

    @Override
    public int incrementViewCount(Integer id) {
        return wzMapper.incrementViewCount(id);
    }

    @Override
    public int deleteWz(Integer id) {
        return wzMapper.deleteWz(id);
    }
}